<template>
  <view class="goods-item">
    <!-- 左侧图片区域 -->
    <view class="goods-item-left">
      <radio :checked="goods.goods_state" color="#c00000" v-if="showRadio" @click="radioClickHandler" />
      <image :src="goods.goods_small_logo || defaultPic" ></image>
    </view>
    <!-- 右侧商品信息区域 -->
    <view class="goods-item-right">
      <!-- 商品的名称 -->
      <view class="goods-name">{{goods.goods_name}}</view>
      <!-- 商品的信息 -->
      <view class="goods-info-box">
        <view class="goods-price">￥{{goods.goods_price.toFixed(2)}}</view>
        <uni-number-box :min="1" :max="99" :value="goods.goods_count" v-if="showNum" @change="numberClickHandler"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props:{
      // 商品信息对象
      goods:{
        type:Object,
        default:{}
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    data() {
      return {
        // 商品的默认图片地址
        defaultPic:'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    methods:{
      // 点击 radio 的事件
      radioClickHandler(){
        this.$emit('radio-change',{
          goods_id:this.goods.goods_id,
          goods_state:!this.goods.goods_state
        })
      },
      // 点击 number-bar 的事件
      numberClickHandler(val){
        this.$emit('number-change',{
          goods_id: this.goods.goods_id,
          goods_count: +val
        })
      }
    }
  }
</script>

<style lang="scss">
.goods-item{
  display: flex;
  border-bottom: 1px solid #f0f0ff;
  .goods-item-left{
    display: flex;
    align-items: center;
    margin-left: 5px;
    image{
      width: 100px;
      height: 100px;
      display: block;
    }
  }
  .goods-item-right{
    margin:5px;
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-name{
      font-size: 13px;
      font-weight: 500;
    }
    .goods-info-box{
      display: flex;
      justify-content: space-between;
      align-items: center;
      .goods-price{
        font-size: 16px;
        color: #c00000;
        font-weight: 600;
      }
    }
  }
}
</style>